imROIs = zeros(size(segments,1),size(segments,2));
count = 1;
for ind = 1:size(segments,3)
% %     if sum(sum(segments(:,:,ind))) > 150
        imROIs(segments(:,:,ind) > 0) = count;
        count = count + 1;
%     end
end

tempROIs.indices = [];
% tempROIs.Centroid = [];
segments = permute(L,[2 3 1]);
for ind = 1:size(segments,3)
    temp = regionprops(segments(:,:,ind) > 0 , 'Area', 'PixelIdxList');
    tempROIs(ind).indices = cell2mat({temp.PixelIdxList}');
end
tempROIs = ROI_activity(data{2},tempROIs);


count = 1;
segments = permute(L,[2 3 1]);
for ind = 1:size(segments,3)
    temp = regionprops(segments(:,:,ind) > 0 , 'Area', 'PixelIdxList');
    for jnd=1:size(temp,1)
        if temp(jnd).Area > 20
        tempROIs(count).indices = temp(jnd).PixelIdxList;
        tempROIs(count).Area = temp(jnd).Area;
        tempROIs(count).ica = ind;
        count = count + 1;
        end
    end
end
ROIs_ICA_single = ROI_activity(data{2},tempROIs);

%kmeans
matrix_ROIs = zeros(15000,length(ROIs_ICA_single));
idx = kmeans(matrix_ROIs',100);
for ind=1:length(ROIs_ICA_single),ROIs_ICA_single(ind).kmeans = idx(ind);end;

corr_result = zeros(length(ROIs_ICA_single));
for ind = 1:length(ROIs_ICA_single)
    for jnd = ind + 1:length(ROIs_ICA_single)
        corr_result(ind,jnd) = corr2(ROIs_ICA_single(ind).activity,ROIs_ICA_single(jnd).activity);
    end
end
